import {observable, action} from 'mobx';
import { WeaTools } from 'ecCom';
import * as API_LIST from '../apis/rptHistory'
import {WeaTableNew} from 'comsMobx'
const {TableStore} = WeaTableNew;
import * as mobx from 'mobx'


/**
 * 共享模态框的store
 */
export class ShareModalStore {

	 /** 列表store */
    @observable loading = false;
    @observable title = "";
    dataKey = "";
    @observable tableStore = new TableStore();
    modalTitle = ""

    @observable showAute = false;
    @observable condition = [];

    groupGuid1 = "";

    /** 路由 **/
    router = {};

    constructor() {
        this.setLoading = this.setLoading.bind(this);
        this.setTitle = this.setTitle.bind(this);
        this.setShowAute = this.setShowAute.bind(this);
        this.shareInfo = this.shareInfo.bind(this);
        this.addShare = this.addShare.bind(this);
        this.deleteShare = this.deleteShare.bind(this);
        this.setGroupGuid1 = this.setGroupGuid1.bind(this);
    }

    @action
    setLoading(bool = false){
        this.loading = bool;
    }
    
    setTitle(title){
        this.title = title;
    }

    @action
    setShowAute(bool){
        this.showAute = bool;
    }

    setGroupGuid1(value){
        this.groupGuid1 = value;
    }
   
    

    //添加共享
    addShare(params = {},method){
    	API_LIST.shareReport(params).then(data =>{ 
            if(data.flag == 'success'){
                 method({'fnaTmpTbLogId':params.fnaTmpTbLogId,'rptTypeName':params.rptTypeName});
                 this.setShowAute(false);
            }else{
                if(this.router){
                    this.router.push('main/fna/fnaReportPermission');// main/fna/fnaReportPermission  data.url
                }
            }
            this.groupGuid1 = '';
    	});
    }

    //删除共享
    deleteShare(params = {},method){
    	API_LIST.deleteShareReport(params).then(data =>{
    		if(data.flag == 'success'){
                method({'fnaTmpTbLogId':params.fnaTmpTbLogId,'rptTypeName':params.rptTypeName});
            }else{
                if(this.router){
                    this.router.push('main/fna/fnaReportPermission');// main/fna/fnaReportPermission  data.url
                }
            }
    	});
    }

    //共享录入信息
    shareInfo(params = {}){
        API_LIST.queryShareAddInfo(params).then(data =>{
            if(data.flag == 'success'){
                this.condition = data.conditions;          
                this.setShowAute(true);
            }else{
                if(this.router){
                    this.router.push('main/fna/fnaReportPermission');// main/fna/fnaReportPermission  data.url
                }
            }
        });
    } 

    setRouter = (value) => {
        this.router = value;
    }
}